<template>
  <div class="global-header">
    <a-row :wrap="false">
      <a-col flex="200px">
        <div class="title-bar">
          <img class="logo" src="../assets/2Blogo.jpg" alt="logo" />
          <div class="title">鱼皮用户中心</div>
        </div>
      </a-col>
      <a-col flex="720px">
        <a-menu
          v-model:selectedKeys="current"
          mode="horizontal"
          :items="items"
          @click="doMenuClick"
      /></a-col>
      <a-col flex="100px">
        <div class="user-login-status">
          {{ JSON.stringify(store.loginUser) }}
          <a-button type="primary">登录</a-button>
        </div>
      </a-col>
    </a-row>
  </div>
</template>
<script lang="ts" setup>
import { h, ref } from "vue";
import {
  MailOutlined,
  AppstoreOutlined,
  SettingOutlined,
} from "@ant-design/icons-vue";
import { MenuProps } from "ant-design-vue";
import { useRouter } from "vue-router";
import { useCounterStore } from "../store/userLoginStore";

const store = useCounterStore();

const router = useRouter();
// 点击菜单后的路由跳转事件
const doMenuClick = ({ key }: { key: string }) => {
  router.push({
    path: key,
  });
};
const current = ref<string[]>(["mail"]);
router.afterEach((to, from) => {
  // 使用 to.path 或 to.name 更新 current
  current.value = [to.path]; // 或者 current.value = [to.name];
});
const items = ref<MenuProps["items"]>([
  {
    key: "/",
    icon: () => h(MailOutlined),
    label: "主页",
    title: "主页",
  },
  {
    key: "/user/login",
    icon: () => h(AppstoreOutlined),
    label: "用户登录",
    title: "用户登录",
  },
  {
    key: "/user/register",
    icon: () => h(SettingOutlined),
    label: "用户注册",
    title: "用户注册",
    // children: [
    //   {
    //     type: "group",
    //     label: "Item 1",
    //     children: [
    //       {
    //         label: "Option 1",
    //         key: "setting:1",
    //       },
    //       {
    //         label: "Option 2",
    //         key: "setting:2",
    //       },
    //     ],
    //   },
    //   {
    //     type: "group",
    //     label: "Item 2",
    //     children: [
    //       {
    //         label: "Option 3",
    //         key: "setting:3",
    //       },
    //       {
    //         label: "Option 4",
    //         key: "setting:4",
    //       },
    //     ],
    //   },
    // ],
  },
  {
    key: "/admin/userManage",
    icon: () => h(AppstoreOutlined),
    label: "用户管理",
    title: "用户管理",
  },
  {
    key: "alipay",
    label: h(
      "a",
      { href: "https://antdv.com", target: "_blank" },
      "Navigation Four - Link"
    ),
    title: "Navigation Four - Link",
  },
]);
</script>
<style scoped>
.title-bar {
  display: flex;
  align-items: center;
}
.title {
  color: black;
  font-size: 12px;
  margin-left: 12px;
}
.logo {
  height: 48px;
}
</style>
